package com.example.demo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.example.demo.entity.Banners;
import com.example.demo.service.IBannersService;
import com.example.demo.utils.PageResult;
import com.example.demo.utils.PassToken;
import com.example.demo.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * bannersController
 * 
 * @author ruoyi
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/system/banners")
public class BannersController
{
    @Autowired
    private IBannersService bannersService;

    /**
     * 查询banners列表
     */
    @PassToken
    @GetMapping("/list")
    public ResponseResult list(Banners banners, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "3")int pageSize)
    {
        PageResult pageResult=bannersService.selectBannersList(banners,pageNum,pageSize);

        return ResponseResult.createBySuccess(200,pageResult,"获取成功");
    }

    /**
     * 导出banners列表
     */
//    @PreAuthorize("@ss.hasPermi('system:banners:export')")
//    @Log(title = "banners", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Banners banners)
//    {
//        List<Banners> list = bannersService.selectBannersList(banners);
//        ExcelUtil<Banners> util = new ExcelUtil<Banners>(Banners.class);
//        util.exportExcel(response, list, "banners数据");
//    }

    /**
     * 获取banners详细信息
     */

    @GetMapping(value = "/{id}")
    public ResponseResult getInfo(@PathVariable("id") Long id)
    {Banners banners=bannersService.selectBannersById(id);
        return ResponseResult.createBySuccess(200,banners,"查询成功");
    }

    /**
     * 新增banners
     */

    @PostMapping
    public ResponseResult add(@RequestBody Banners banners) {
        int i = bannersService.insertBanners(banners);
        if (i > 0) {
            return ResponseResult.createBySuccess(200, "", "添加成功");
        } else {
            return ResponseResult.createByFail(500, "添加失败");
        }
    }
        /**
         * 修改banners
         */

        @PutMapping
        public ResponseResult edit(@RequestBody Banners banners)
        {
            int i = bannersService.updateBanners(banners);
            if (i > 0) {
                return ResponseResult.createBySuccess(200, "", "更新成功");
            } else {
                return ResponseResult.createByFail(500, "更新失败");
            }
        }

        /**
         * 删除banners
         */

        @DeleteMapping("/{ids}")
        public ResponseResult remove (@PathVariable Long[] ids)
        {
            int i = bannersService.deleteBannersByIds(ids);
            if (i > 0) {
                return ResponseResult.createBySuccess(200, "", "删除成功");
            } else {
                return ResponseResult.createByFail(500, "删除失败");
            }
        }
    }
